/**
 * 
 */
package jp.tkym.labs.util.beankey;

import java.io.Serializable;
import java.util.Arrays;

public class BeanKey implements Serializable{
	/**  */
	private static final long serialVersionUID = -7010145981220233882L;
	
	private Object[] values;
	
	private int length;
	private Object key0;
	private Object key1;
	private Object key2;
	private Object key3;
	private Object key4;
	
	public BeanKey(Object...values){
		this.values = values;
		this.length = this.values.length;
		if(length > 0) { key0 = this.values[0]; } 
		if(length > 1) { key1 = this.values[1]; } 
		if(length > 2) { key2 = this.values[2]; } 
		if(length > 3) { key3 = this.values[3]; } 
		if(length > 4) { key4 = this.values[4]; } 
	}
	
	public Object[] values(){
		return values;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Arrays.hashCode(values);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BeanKey other = (BeanKey) obj;
		if(length != other.length) return false;
		if(length == 1){
			if(!key0.equals(other.key0)) return false;
		}else if(length == 2){
			if(!key0.equals(other.key0)) return false;
			if(!key1.equals(other.key1)) return false;
		}else if(length == 3){
			if(!key0.equals(other.key0)) return false;
			if(!key1.equals(other.key1)) return false;
			if(!key2.equals(other.key2)) return false;
		}else if(length == 4){
			if(!key0.equals(other.key0)) return false;
			if(!key1.equals(other.key1)) return false;
			if(!key2.equals(other.key2)) return false;
			if(!key3.equals(other.key3)) return false;
		}else if(length == 5){
			if(!key0.equals(other.key0)) return false;
			if(!key1.equals(other.key1)) return false;
			if(!key2.equals(other.key2)) return false;
			if(!key3.equals(other.key3)) return false;
			if(!key4.equals(other.key4)) return false;
		}else{
			if (!Arrays.deepEquals(values, other.values)) return false;
		}
		return true;
	}
}